import SystemUtil from 'utils/systemUtil';

var config;

const loadFile = lang => {
  config = require(`./config/${lang}/index`).default;
};

loadFile('zh-cn');

export default class {
  static locale(lang) {
    loadFile(lang);
  }

  static getMsg(code) {
    if (typeof code !== 'string') {
      throw new Error('i18n getMsg field code is not string');
    }

    let value = SystemUtil.getPropByPath(config, code, '');
    return value;
  }

  static getDropDown(path, attrs) {
    let dropDown = [];
    for (let i = 0; i < attrs.length; i++) {
      const attr = array[i];
      let label = this.getMsg(`${path}.${attr}`);
      dropDown.push({
        label: label,
        value: attr
      });
    }

    return dropDown;
  }
};
